<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>$watch数据监听 </title>
		<script src="../org/angular.min.js" ></script>
	</head>
	<body>
		<div ng-app = "hd" ng-controller = "ctrl">
			标题：<input type="text" ng-model="news.title" />{{error}}
		</div> 
		<script>
			var m = angular.module('hd',[]);
			m.controller('ctrl',['$scope',function($scope){
				
//				$scope.title = "";
//				$scope.$watch("title",function(n,o){
//					if($scope.title.length>3){
//						$scope.error = "标题不能超过三位";
//					}
//				});

                $scope.news = {title:""};
                $scope.$watch("news",function(n,o){
                	if($scope.news.title.length>3){
                		$scope.error = "标题不能超过三位";
                	}
                },true);
			}]);
		</script>
	</body>
</html>
